package com.uroboros.spring.guides.rest;

import com.uroboros.spring.guides.rest.employee.Employee;
import com.uroboros.spring.guides.rest.employee.EmployeeRepository;
import com.uroboros.spring.guides.rest.employee2.Employee2;
import com.uroboros.spring.guides.rest.employee2.Employee2Repository;
import com.uroboros.spring.guides.rest.order.Order;
import com.uroboros.spring.guides.rest.order.OrderRepository;
import com.uroboros.spring.guides.rest.order.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class LoadDatabase {

  private static final Logger log = LoggerFactory.getLogger(LoadDatabase.class);

  @Bean
  public CommandLineRunner initEmployee(EmployeeRepository repository) {
    return args -> {
      log.info("Preloading " + repository.save(new Employee("Bilbo Baggins", "burglar")));
      log.info("Preloading " + repository.save(new Employee("Frodo Baggins", "thief")));
    };
  }

  @Bean
  public CommandLineRunner initEmployee2(Employee2Repository repository) {
    return args -> {
      log.info("Preloading " + repository.save(new Employee2("Bilbo", "Baggins", "burglar")));
      log.info("Preloading " + repository.save(new Employee2("Frodo", "Baggins", "thief")));
    };
  }

  @Bean
  public CommandLineRunner initOrder(OrderRepository repository) {
    return args -> {
      log.info("Preloading " + repository.save(new Order("MacBook Pro", Status.COMPLETED)));
      log.info("Preloading " + repository.save(new Order("iPhone", Status.IN_PROGRESS)));
    };
  }

}
